<template>
	<view class="assemblyOrder-container">
		<view class="dome pt20 pb50 pl20 pr20 ">
			<view class="flex mb10">
				<view class="w200">
					生产单号:
				</view>
				<view class="w480" style="word-break: break-word;">
					{{ info.orderCode || '' }}
				</view>
			</view>

			<view class="flex mb10">
				<view class="w200">
					制单日期:
				</view>
				<view class="w480" style="word-break: break-word;">
					{{ info.createTime || '' }}
				</view>
			</view>

			<view class="flex mb10">
				<view class="w200">
					交货日期:
				</view>
				<view class="w480" style="word-break: break-word;">
					{{ info.deliveryDate || '' }}
				</view>
			</view>

			<view class="flex mb10">
				<view class="w200">
					产品名称:
				</view>
				<view class="w480" style="word-break: break-word;">
					{{ info.productName || '' }}
				</view>
			</view>

			<view class="flex mb10">
				<view class="w200">
					生产数量:
				</view>
				<view class="w480" style="word-break: break-word;">
					{{ info.number || '' }}
				</view>
			</view>

			<view class="flex mb10">
				<view class="w200">
					备注:
				</view>
				<view class="w480" style="word-break: break-word;">
					{{ info.remark || '' }}
				</view>
			</view>
		</view>

		<view class="dome pt20 pb50 pl20 pr20 " style="margin-top: 50rpx;">
			<view class="mb10" style="text-align: center;font-weight: bold;">
				当前生产进度已全部完成
			</view>

			<view class="flex mb10">
				<view class="w200">
					订单数量:
				</view>
				<view class="w480" style="word-break: break-word;">
					{{ info.number || '' }}
				</view>
			</view>

			<view class="flex mb10">
				<view class="w200">
					完成数量:
				</view>
				<view class="w480" style="word-break: break-word;">
					{{ info.inNumber || '' }}
				</view>
			</view>



			<view class="aCenter mb10">
				<view class="w200">
					验收入库数量:
				</view>
				<view class="w480" style="word-break: break-word;">
					<u--input placeholder="请输入验收入库数量" border="surround" v-model="number"></u--input>
				</view>
			</view>

			<view class="flex mb10">
				<u-checkbox-group v-model="checked" placement="column">
					<u-checkbox shape="circle" name="checked" label="已完全验收"></u-checkbox>
				</u-checkbox-group>
			</view>

			<view class="text">
				注意:验收入库人对产品的最终数量负责，请谨慎输入最终验收入库数量
			</view>


			<view class="jCenter" style="margin-top: 50rpx;">
				<view class="" style="width: 120rpx;">
					<u-button @click="handleConfirm" type="primary" plain text="确认" size="small"></u-button>
				</view>
			</view>
		</view>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: '',
				ids: '',
				info: {},
				checked: [],
				number: '',
			}
		},
		onLoad(e) {
			this.type = e.type
			this.ids = e.id
			this.handleWarehousing()
		},
		methods: {
			async handleConfirm() {

				const interfaceUrl = {
					1: `/system/bomProductionOrder/checkIn?number=${this.number}&id=${this.ids}&completeFlag=${this.checked.length}`,
					2: `/system/customizedProduct/checkIn?number=${this.number}&id=${this.ids}&completeFlag=${this.checked.length}`,
					3: `/system/auxiliaryPackingOrder/checkIn?number=${this.number}&id=${this.ids}&completeFlag=${this.checked.length}`,
					4: `/system/customizedChildrenOrder/checkIn?number=${this.number}&id=${this.ids}&completeFlag=${this.checked.length}`,
					5: `/system/customizedChildrenOrder/checkIn?number=${this.number}&id=${this.ids}&completeFlag=${this.checked.length}`,
					6: `/system/customizedChildrenOrder/checkIn?number=${this.number}&id=${this.ids}&completeFlag=${this.checked.length}`,
				}


				if (!this.number) return this.$msg.error('请输入入库数量')
				try {
					if (this.type == 8 || this.type == 7) {

						const typeUrl = {
							8: `/system/auxiliaryCustomizedOrder/checkIn?number=${this.number}&id=${this.ids}&completeFlag=${this.checked.length}`,
							7: `/system/auxiliaryCustomizedOrder/checkIn?number=${this.number}&id=${this.ids}&completeFlag=${this.checked.length}`,
						}

						await this.$api.microCustomizationAcceptanceAndStorageApi(typeUrl[this.type])

						this.$msg.success('入库成功')
						setTimeout(() => {
							uni.switchTab({
								url: '/pages/index/index'
							})
						}, 1000)
					} else {
						await this.$api.checkInStorageApi(interfaceUrl[this.type])

						this.$msg.success('入库成功')
						setTimeout(() => {
							uni.switchTab({
								url: '/pages/index/index'
							})
						}, 1000)
					}


				} catch (error) {
					//TODO handle the exception
				}
			},
			async handleWarehousing() {
				try {
					const {
						data
					} = await this.$api.getAcceptanceAndStorageDetails(this.ids + '-' + this.type)

					this.info = data
				} catch (error) {
					//TODO handle the exception
					console.log(error, '报错')
				}
			},
		}
	}
</script>

<style scoped lang="scss">
	.assemblyOrder-container {
		width: 100%;
		min-height: 100vh;
		background-color: #F5F5F5;

		.dome {
			background-color: #FFFFFF;
			border-radius: 8rpx;
			margin: 10rpx auto;
			width: 710rpx;
			border: 1rpx solid #C8C8C8;
		}

		.text {
			width: 100%;
			text-align: center;
			color: #F76C5F;
			font-size: 26rpx;
			margin-top: 40rpx;
		}
	}

	.mb10 {
		margin-bottom: 20rpx !important;
	}
</style>